package com.zpc.myvideoserver.common.security.handler;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.zpc.myvideoserver.common.util.ResponseJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName : LoginFailureHandler  //类名
 * @Description : 登录失败处理类  //描述
 * @Author : zpc20 //作者
 * @Date: 2023/11/1  22:47
 */
@Component
public class LoginFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        /**
        * @Param : errorMessage
        * @Description : 登录错误信息
        * @Date: 2023/11/1
        */
        String errorMessage = "用户名或密码错误";
        ResponseJson.FailResponse(response,errorMessage);
    }
}
